package com.yesallchina.wxapp.officialaccount.api.beans;



import com.yesallchina.wxapp.officialaccount.api.enums.MessageEventTypeEnum;
import com.yesallchina.wxapp.officialaccount.utils.JacksonUtils;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.HashMap;
import java.util.Map;

@XmlRootElement(name = "xml")
public class VideoMessage extends Message {

	private String MediaId;
	private String ThumbMediaId;
	private Video Video;

	public VideoMessage(){
		super();
		super.setMsgType(MessageEventTypeEnum.VIDEO.getMsgType());
	}

	public VideoMessage(String mediaId,String title,String desc) {
		super();
		super.setMsgType(MessageEventTypeEnum.VIDEO.getMsgType());
		this.Video = new Video();
		this.Video.setMedia_id(mediaId);
		this.Video.setDescription(desc);
		this.Video.setTitle(title);
	}

	@XmlElement(name = "MediaId")
	public String getMediaId() {
		return MediaId;
	}

	public void setMediaId(String mediaId) {
		MediaId = mediaId;
	}

	@XmlElement(name = "ThumbMediaId")
	public String getThumbMediaId() {
		return ThumbMediaId;
	}

	public void setThumbMediaId(String thumbMediaId) {
		ThumbMediaId = thumbMediaId;
	}

	@XmlElement(name = "Video")
	public VideoMessage.Video getVideo() {
		return Video;
	}

	public void setVideo(VideoMessage.Video video) {
		Video = video;
	}

	public static class Video {
		private String media_id;
		private String title;   
		private String description;

		@XmlElement(name="media_id")
		public String getMedia_id() {
			return media_id;
		}

		public void setMedia_id(String media_id) {
			this.media_id = media_id;
		}

		@XmlElement(name="title")
		public String getTitle() {
			return title;
		}

		public void setTitle(String title) {
			this.title = title;
		}

		@XmlElement(name="description")
		public String getDescription() {
			return description;
		}

		public void setDescription(String description) {
			this.description = description;
		}

	}

	@Override
	public String toCustomerMessage() {
		Map<String, Object> msg = new HashMap<>();
		msg.put("touser", getToUserName());
		msg.put("msgtype", MessageEventTypeEnum.VIDEO.getMsgType());
		Map<String, Object> video = new HashMap<>();
		video.put("media_id", getMediaId());
		video.put("thumb_media_id",getThumbMediaId());
		video.put("title",getVideo().getTitle());
		video.put("description",getVideo().getDescription());
		msg.put("video", video);
		return JacksonUtils.generate(msg);
	}
}
